package org.surelink.radius;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.surelink.radius.api.thrift.ApiService;
import org.surelink.radius.api.thrift.TClient;
import org.surelink.radius.api.thrift.TUser;

public class ApiClientDemo
{
    public void startClient() {
        TTransport transport;
        try {
            transport = new TSocket("localhost", 1815);
            TProtocol protocol = new TBinaryProtocol(transport);
            ApiService.Client client = new ApiService.Client(protocol);
            transport.open();

            TUser user = new TUser();
            user.setUserName("testuser");
            user.setPassword("123456");
            user.setGroupName("default");
            client.setUser(user);

            TClient tc = new TClient();
            tc.setAddress("192.168.1.101");
            tc.setSecret("secret");
            tc.setClientType("huawei");
            tc.setClientDesc("huawei bas");
            client.setClient(tc);

            transport.close();
        } catch (TTransportException e) {
            e.printStackTrace();
        } catch (TException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ApiClientDemo client = new ApiClientDemo();
        client.startClient();
    }

}
